/**
 *  @file ship.h
 *
 *  @date 16-nov-2009
 *  @author Ives van der Flaas
 */

#ifndef SHIP_H_
#define SHIP_H_

#include <vector>
#include <tr1/memory>
#include "sprite.h"
#include "vector2.h"
#include "projectile.h"


namespace si
{
/**
 * A general ship that can shoot bullets and be killed.
 */
class Ship: public si::Sprite
{
public:
	friend class CollisionDetector;
	/**
	 * Ctor
	 * @param startHealth Health the ship will start with
	 * @param virtualSize The virtual size of the ship
	 * @return
	 */
	Ship(int startHealth, Vector2 virtualSize);
	virtual ~Ship();

	/**
	 * Diminishes this ships health with parameter
	 * @param hitAmount The amount to be subtracted from health
	 */
	virtual void takeHit(int hitAmount);

	/**
	 * Returns true when this ship is ready to be erased...
	 * @return
	 */
	virtual bool deleteMe();

	/**
	 * Will move bullets & call sprite::update
	 * @param time
	 */
	virtual void update(double time);
	/**
	 * Will draw bullets and call sprite::draw
	 */
	virtual void draw() const;

	/**
	 * Should reset a ship to its original health, position and so on.
	 */
	virtual void reset(){ fBullets.clear();};

	/**
	 * Will be called when a bullet hit target
	 * @param whichBullet The bullet that hit
	 */
	virtual void bulletHit(unsigned int whichBullet);

	/**
	 * Will be called when the ship dies.
	 */
	virtual void justDied();
protected:
	/**
	 * The amount of life still in this ship. For friendly's this'll be
	 * bigger than for for normal enemy ships.
	 */
	int fHealth;

	/**
	 * Health this ship will start with.
	 */
	int fStartHealth;


	/**
	 * Will be overloaded to create a new bullet for this kind of ship...
	 * @return shared_ptr to that bullet
	 */
	virtual std::tr1::shared_ptr<Projectile> newBullet()=0;


	/**
	 * Makes a new bullet and fires it.
	 */
	virtual void fire();

private:
	std::vector<std::tr1::shared_ptr<Projectile> > fBullets;
};

}

#endif /* SHIP_H_ */
